#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

std::string path = "/dev/pts/2";

void Redirect()
{
    // 需要向里面写，所以，不能用O_RDONLY
    int fd = open(path.c_str(), O_WRONLY);
    if(fd < 0)
    {
        std::cerr << "open error" << std::endl;
        exit(1);
    }
    dup2(fd, 2);
}